package com.redhat.auth.web.role;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.redhat.auth.application.RoleApplication;
import com.redhat.auth.domain.Role;
import com.redhat.redwork.widget.grid.AbstractGridModel;
import com.redhat.redwork.widget.grid.Order;

@Service(value="roleGridModel")
public class RoleGridModel extends AbstractGridModel<Role, Role> {
	
	private static final Logger	logger  = LoggerFactory.getLogger(RoleGridModel.class);

	@Autowired
	private RoleApplication roleAppliaction;
	
	@Override
	public Long count(Role search) {
		return roleAppliaction.getCount(search);
	}

	@Override
	public void delete(String id) {
		try {
			roleAppliaction.deleteRoleById(Long.parseLong(id));
		} catch (Exception e) {
			logger.error("",e);
			throw new RuntimeException("删除失败");
		}
	}

	@Override
	public Role getCriteriaObject() {
		return new Role();
	}

	@Override
	public List<Role> list(Role search, int page, int pageSize, Order order) {
		return roleAppliaction.queryAllByPage(search, page, pageSize);
	}

	
}
